-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.x] Validate version and variant in Str::isUuid()
#48321
Conversation
Never looked into it, but since laravel comes with Ramsey's Uuid package, why not use it's isValid method? |
I took a peek and Ramsey's package has the same, more generic, expression. The uuidjs package uses this same approach, though. |
Could this be a breaking change for UUIDs that Laravel currently generates like "ordered" UUIDs, etc.? |
I checked ordered uuids and they’re fine. I was 99% sure they’d be unaffected, but I also tested a few million random ordered UUIDs just in case. Are there other formats that I should double-check? |
Str::uuid and Str::orderedUuid are the only Laravel UUID methods, so I don't think so. |
@@ -516,7 +516,11 @@ public static function isUuid($value) | |||
return false; | |||
} | |||
|
|||
return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0; | |||
if ($value === '00000000-0000-0000-0000-000000000000') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we allowing this bad null value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NIL UUID is valid per the RFC.
This reverts commit 1591fed.
This PR introduced a breaking change for ULIDs that are converted to UUID. |
@frodeknutsen we've reverted this in https://github.com/laravel/framework/releases/tag/v10.23.1 |
I'd say re-add it, but use strict in some way? |
Why not just compare against |
Why? It's a valid UUID as per https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.7 I expect an |
Right now,
Str::isUuid()
will returntrue
for UUIDs that are not RFC4122-compliant. In addition to the 8-4-4-4-12 format, UUIDs have two special characters:1–5
8
,9
,a
, orb
(These special values are actually defined by specific bits in the UUID, but in practice it works out to the above rules.)
Here are two UUIDs that look valid but actually are not:
This PR updates the regular expression to account for these constraints on validity. It also accounts for the one outlier case, which is the "NIL" UUID
00000000-0000-0000-0000-000000000000
. Rather than complicating the regular expression, I've just added an additional check for this exact string, because it's the only of its kind.